﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.Mvc;
using System.IO;
using System.Collections;
using FlowBasis.Json;

namespace FlowBasis.Web.Mvc
{

    /// <summary>
    /// If PostRpcAttribute is applied to a controller action, it will return exceptions
    /// as PostRpcResult exceptions.
    /// </summary>
    public class PostRpcAttribute : ActionFilterAttribute
    {
        public override void OnActionExecuting(ActionExecutingContext context)
        {
            base.OnActionExecuting(context);
        }

        public override void OnActionExecuted(ActionExecutedContext context)
        {
            base.OnActionExecuted(context);
            
            if (context.Exception != null)
            {                
                context.Result = new PostRpcResult(context.Exception);
                context.ExceptionHandled = true;
            }
        }
    }
}
